package br.com.academix.shell.view
{
	import br.com.academix.commons.PipeAwareModuleConstants;
	
	import flash.display.DisplayObject;
	
	import mx.modules.IModuleInfo;
	
	import org.puremvc.as3.multicore.interfaces.IMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;

	public class AcademixRIAMediator extends Mediator implements IMediator
	{
		public static const NAME:String = "PureMVCSamplesMediator";
		private var _sampleModule:IModuleInfo;
		public var module_loaded:Boolean = false;
		public var module_instance:DisplayObject;
		
		public function AcademixRIAMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
		}
		
		override public function onRegister():void{
		}
		
		  
        /* private function loadModule(module:String):void{
        	
            switch (module)
            {
                case PureMVCSampleConstants.MODULE:
                    if( !_sampleModule || !_sampleModule.loaded )
                    {
                        _sampleModule = ModuleManager.getModule( PureMVCSampleConstants.MODULE_URL );
                        _sampleModule.addEventListener( ModuleEvent.READY, onModuleReady );
                        _sampleModule.load();
                    }
                    else
                    {
                    	_sampleModule.addEventListener( ModuleEvent.UNLOAD, onModuleUnload );
                        _sampleModule.unload();
                    }
                    break;
            }
		
        }
        
        private function onModuleReady(evt:ModuleEvent):void{
        	switch ( evt.module )
            {
                case _sampleModule:
                    module_instance = _sampleModule.factory.create() as ModuleSample;
                    app.moduleContainer.addChild( module_instance );
                    module_loaded = true;
                    _sampleModule.removeEventListener( ModuleEvent.READY, onModuleReady );
                    sendNotification( PureMVCSampleConstants.MODULE_ADDED, module_instance );
		            
                break;
            }
                                        
            CursorManager.removeBusyCursor();
        }
        
        private function onModuleUnload(evt:ModuleEvent):void{
        	    switch ( evt.module )
                {
                    case _sampleModule:
                        _sampleModule.removeEventListener( ModuleEvent.UNLOAD, onModuleUnload );
                        app.moduleContainer.removeChild( module_instance );
            			sendNotification(PipeAwareModuleConstants.REMOVE_MODULE);
                        sendNotification(PureMVCSampleConstants.MODULE_REMOVED);
            			_sampleModule = null;
                        module_loaded = false;
                        app.txtInfo.text = "";
                        break;
                }
                            
                CursorManager.removeBusyCursor();
        } */
		
		override public function listNotificationInterests():Array{
			return[PipeAwareModuleConstants.SEND_MESSAGE_SHELL];
		}
		
		override public function handleNotification(notification:INotification):void{
			switch(notification.getName()){
				default: break;
			}
		}
		
		 public function get app():AcademiaRIA{
			return viewComponent as AcademiaRIA;
		} 
		
	}
}